/*  This file is Copyright 2010 Hampton Smith
 *
 *  This file is part of Adventure! a text-adventure game engine by Hampton
 *  Smith.
 *
 *  Adventure! is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Adventure! is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Adventure!.  If not, see http://www.gnu.org/licenses/.
 */

package edu.clemson.cs.hamptos.adventure;

/**
 * <p>An <code>AdventureCommand</code> represents a parsed version of the text
 * commands the user provides, in which the textual references to game
 * objects have already been resolved to the game objects themselves (i.e., to
 * <code>AdventureTarget</code>s.)</p>
 *
 * <p>Commands can have three different parts: a <em>verb</em>, which indicates
 * what should be done, a <em>direct object</em>, which indicates what the verb
 * should be done to, and an <em>indirect object</em>, which indicates with what
 * the verb should be done to the direct object with.  So, for example, in this
 * command:</p>
 *
 * <pre>unlock door with key</pre>
 *
 * <p>"unlock" is the verb, "door" is the direct object, and "key" is the
 * indirect object.</p>
 *
 * <p>Because there can be confusion between the game object the player
 * indicates and the <em>text</em> that the player uses to refer to that game
 * object, we will use "direct object" or "indirect object" to refer to game
 * objects and "direct object <em>invocation</em>" and "indirect object
 * <em>invocation</em>" to refer to the <em>text</em> the user used.</p>
 */
public final class AdventureCommand {

    private String myVerb;
    private AdventureTarget myDirectObject;
    private final String myDirectInvocation;

    private AdventureTarget myIndirectObject;
    private final String myIndirectInvocation;

    /**
     * <p>Creates a new <code>AdventureCommand</code> that has no direct or
     * indirect object.  This would be a command like "wait" or "look".</p>
     *
     * <p>Such a command will be routed to the player's current location for
     * processing.</p>
     *
     * @param verb The verb.
     */
    public AdventureCommand(String verb) {
        this(verb, null, null);
    }

    /**
     * <p>Creates a new <code>AdventureCommand</code> that has a direct object
     * but no indirect object.  This would be a command like "take torch" or
     * "eat cake".</p>
     *
     * <p>Such a command will be routed to the direct object for processing.</p>
     *
     * @param verb The verb.
     * @param directObject The game object representing the direct object.
     * @param directInvocation The text the player used to refer to the direct
     *    object.
     */
    public AdventureCommand(String verb, AdventureTarget directObject, 
            String directInvocation) {

        this(verb, directObject, directInvocation, null, null);
    }

    /**
     * <p>Creates a new <code>AdventureCommand</code> that has a direct object
     * and an indirect object.  This would be a command like "light torch with
     * the match" or "unlock the door with the key".</p>
     *
     * <p>Such a command will be routed to the indirect object for processing.
     * </p>
     *
     * @param verb The verb.
     * @param directObject The game object representing the direct object.
     * @param directInvocation The text the player used to refer to the direct
     *    object.
     * @param indirectObject The game object representing the indirect object.
     * @param indirectInvocation The text the player used to refer to the 
     *    indirect object.
     */
    public AdventureCommand(String verb, AdventureTarget directObject, 
            String directInvocation, AdventureTarget indirectObject,
            String indirectInvocation) {

        myVerb = verb.toLowerCase();
        myDirectObject = directObject;
        myIndirectObject = indirectObject;

        myDirectInvocation = directInvocation;
        myIndirectInvocation = indirectInvocation;
    }

    /**
     * <p>Returns the verb.</p>
     *
     * @return The verb.
     */
    public String getVerb() {
        return myVerb;
    }

    /**
     * <p>Returns the direct object, or <code>null</code> if there was no
     * direct object..</p>
     *
     * @return The direct object.
     */
    public AdventureTarget getDirectObject() {
        return myDirectObject;
    }

    /**
     * <p>Returns the indirect object, or <code>null</code> if there was no
     * indirect object..</p>
     *
     * @return The indirect object.
     */
    public AdventureTarget getIndirectObject() {
        return myIndirectObject;
    }

    /**
     * <p>Returns the direct object invocation, or <code>null</code> if there
     * was no direct object..</p>
     *
     * @return The direct object invocation.
     */
    public String getDirectObjectInvocation() {
        return myDirectInvocation;
    }

    /**
     * <p>Returns the indirect object invocation, or <code>null</code> if there
     * was no indirect object..</p>
     *
     * @return The indirect object invocation.
     */
    public String getIndirectObjectInvocation() {
        return myIndirectInvocation;
    }
}
